package com.bearingnavi.android.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;

import com.bearingnavi.android.R;
import com.bearingnavi.android.overlays.BearingOverlay;
import com.bearingnavi.android.overlays.WayPointOverlay;
import com.bearingnavi.android.util.OverlayUtil;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class LongpressDialog extends Dialog{

	private Overlay closestOverlay;
	private GeoPoint geoPoint;
	private Context context;
	private MapView mapView;
	
	public LongpressDialog(Context context, MapView mapView, Point pos, GeoPoint geoPoint, Overlay closestOverlay) {
		
		super(context);
		this.closestOverlay = closestOverlay;
		this.geoPoint = geoPoint;
		this.context = context;
		this.mapView = mapView;
		
		WindowManager.LayoutParams lp = this.getWindow().getAttributes();

		//lp.x = pos.x;
		//lp.y = pos.y;
		lp.windowAnimations = R.style.DialogAnimation;
		
		this.getWindow().setAttributes(lp);
	}
	
	@Override
	public void onBackPressed() {
    	
		super.onBackPressed();
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		this.setContentView(R.layout.longpress);
		
		LinearLayout CleanCon = (LinearLayout) findViewById(R.id.CleanContainer);
		Button AddBearing = (Button) findViewById(R.id.addBearing);
		Button AddWP = (Button) findViewById(R.id.addWp);
		Button CleanBearing = (Button) findViewById(R.id.cleanBearing);
		Button CleanWP = (Button) findViewById(R.id.cleanWp);
		
		Button Share = (Button) findViewById(R.id.Share);
		
		
		
		AddBearing.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				OverlayUtil.drawBearingLine(mapView, context , null, true, geoPoint);
				LongpressDialog.this.dismiss();
			}
		});
		
		CleanBearing.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				OverlayUtil.cleanBearingLine(mapView, context, ((BearingOverlay) closestOverlay).getIndex());
				LongpressDialog.this.dismiss();
			}
		});
		
		AddWP.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				OverlayUtil.addWayPoint(mapView, context, null, true, geoPoint);
				LongpressDialog.this.dismiss();
			}
		});
		
		CleanWP.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				OverlayUtil.cleanWaypoint(mapView, context, ((WayPointOverlay) closestOverlay).getIndex());
				LongpressDialog.this.dismiss();
			}
		});
		
		
		if (closestOverlay == null)
		{
			Share.setVisibility(Button.GONE);
			CleanCon.setVisibility(LinearLayout.GONE);
		}
		else
		{
			if (closestOverlay instanceof WayPointOverlay)
			{
				AddWP.setVisibility(Button.GONE);
				CleanBearing.setVisibility(Button.GONE);
			}
			
			if (closestOverlay instanceof BearingOverlay)
			{
				AddBearing.setVisibility(Button.GONE);
				CleanWP.setVisibility(Button.GONE);
			}
		
		}
	}
	
}
